package com.yijiu.trb;

import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;

import com.yijiu.utils.DialogUtils;

/**
 * 绑定银行卡
 * 
 * @author TangChao_Lenovo
 */
public class BindToBankCardActivity extends BTitleActivity implements OnClickListener
{
	private TextView agreeTextView, agreeButton, login_binding;

	private CheckBox checkBox;

	private Button btnAgree;

	private Button btnLogin;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		getWindow().setFormat(PixelFormat.RGBA_8888);
		setContentView(R.layout.binding_to_bank_card_layout);
		initWidget();
	}

	protected void initWidget()
	{
		super.initWidget();
		titleView.setText("绑定银行卡");
		checkBox = (CheckBox) findViewById(R.id.cb_binding_to_bank_card_isagree);
		agreeTextView = (TextView) findViewById(R.id.agree_textView);
		agreeButton = (TextView) findViewById(R.id.agree_button);
		login_binding = (TextView) findViewById(R.id.login_binding);
		agreeTextView.setOnClickListener(this);
		agreeButton.setOnClickListener(this);
		login_binding.setOnClickListener(this);
		SpannableString sp = new SpannableString("已阅读并同意《电子商务交易转账服务条款》");
		sp.setSpan(new CheckAgreeText(""), 7, 19, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		sp.setSpan(new ForegroundColorSpan(Color.BLACK), 7, 20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		agreeTextView.setText(sp);
		agreeTextView.setMovementMethod(LinkMovementMethod.getInstance());
		btnAgree = (Button) findViewById(R.id.agree_button);
		btnLogin = (Button) findViewById(R.id.login_binding);
		checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
		{
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
			{
				if (isChecked)
				{
					btnAgree.setEnabled(true);
					btnAgree.setBackgroundResource(R.drawable.login_background);
					btnLogin.setEnabled(true);
					btnLogin.setBackgroundResource(R.drawable.register_background);
				}
				else
				{
					btnAgree.setEnabled(false);
					btnAgree.setBackgroundResource(R.drawable.btn_login_bg_false);
					btnLogin.setEnabled(false);
					btnLogin.setBackgroundResource(R.drawable.btn_login_bg_false);
				}
			}
		});
	}

	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
			case R.id.agree_button:
				initIntent(this, AddBankCardOther.class);
				break;
			case R.id.login_binding:
				break;
			default:
				break;
		}
	}

	class CheckAgreeText extends URLSpan
	{
		public CheckAgreeText(String src)
		{
			super(src);
		}

		@Override
		public void onClick(View widget)
		{
			DialogUtils.showAgreeTxtDialog(BindToBankCardActivity.this, R.string.txt1);
		}
	}
}
